<template>
  <Form :form="form">
    <SchemaField :schema="schema"/>
    <Submit @submit="onSubmit">提交</Submit>
  </Form>
</template>

<script lang="ts">
import { createForm } from '@formily/core'
import { createSchemaField } from '@formily/vue'
import { Form, FormItem, Radio, Submit, Space } from '@formily/vxe-table/src'

const {SchemaField} = createSchemaField({
  components: {
    FormItem,
    Radio,
    Space
  },
})

export default {
  components: {Form, SchemaField, Submit},
  data() {
    const schema = {
      type: 'object',
      properties: {
        section1: {
          type: 'void',
          'x-component': "Space",
          'x-component-props': {style: {marginTop: '5px'}},
          properties: {
            section1radio: {
              type: 'number',
              'x-component': 'Radio',
              'x-component-props': {
                label: 1,
                name: 'n1',
                content: '默认尺寸',
              }
            },
            section1radioo: {
              'x-component': 'Radio',
              'x-component-props': {
                label: 2,
                name: 'n1',
                content: '中等尺寸',
                size: 'medium'
              }
            },
            section1radiooo: {
              'x-component': 'Radio',
              'x-component-props': {
                label: 3,
                name: 'n1',
                content: '小型尺寸',
                size: 'small'
              }
            },
            section1radioooo: {
              'x-component': 'Radio',
              'x-component-props': {
                label: 4,
                name: 'n1',
                content: '超小尺寸',
                size: 'mini'
              }
            },
          }
        },
        section2: {
          type: 'void',
          'x-component': "Space",
          'x-component-props': {style: {marginTop: '5px'}},
          properties: {
            section2radio: {
              type: 'number',
              'x-component': 'Radio',
              'x-component-props': {
                label: 1,
                name: 'n2',
                content: '单选1',
              }
            },
            section2radioo: {
              'x-component': 'Radio',
              'x-component-props': {
                label: 2,
                name: 'n2',
                disabled: true,
                content: '禁用2',
              }
            },
            section2radiooo: {
              'x-component': 'Radio',
              'x-component-props': {
                label: 3,
                name: 'n2',
                content: '单选3',
              }
            },
          }
        },
        section3: {
          type: 'boolean',
          title: '单选',
          enum: [
            'HTML', 'CSS', 'JavaScript', 'SASS', 'LESS'
          ],
          'x-component': 'Radio.Group',
          'x-component-props': {style: {marginTop: '5px'}},
        },
        section4: {
          type: 'boolean',
          title: '单选',
          enum: [
            '支持取消1', '支持取消2', '支持取消3',
          ],
          'x-component': 'Radio.Group',
          'x-decorator': 'Space',
          'x-decorator-props': {style: {marginTop: '5px'}},
          'x-component-props': {
            strict: false
          },
        },
        section5: {
          type: 'void',
          'x-component': 'Space',
          'x-component-props': {style: {marginTop: '5px', marginBottom: '5px'}},
          properties: {
            section5radio: {
              type: 'boolean',
              enum: [
                '按钮1', '按钮2', '按钮3',
              ],
              'x-component': 'Radio.Group',
              'x-component-props': {
                optionType: 'button'
              },
            },
            section5radioo: {
              type: 'boolean',
              enum: [
                '支持取消1', '支持取消2', '支持取消3',
              ],
              'x-component': 'Radio.Group',
              'x-component-props': {
                strict: false,
                size: 'medium',
                optionType: 'button'
              },
            },
            section5radiooo: {
              type: 'boolean',
              enum: [
                '按钮1', '按钮2', '按钮3',
              ],
              'x-component': 'Radio.Group',
              'x-component-props': {
                size: 'small',
                optionType: 'button'
              },
            },
            section5radioooo: {
              type: 'boolean',
              enum: [
                '按钮1', '按钮2', '按钮3',
              ],
              'x-component': 'Radio.Group',
              'x-component-props': {
                size: 'mini',
                optionType: 'button'
              },
            }
          }
        },
      },
    }

    const form = createForm()

    return {
      form,
      schema,
    }
  },
  methods: {
    onSubmit(value) {
      console.log(value)
    },
  },
}
</script>
